package edu.zut.hb.ambition.caigou.spring.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import common.annotation.Log;
import common.core.controller.BaseController;
import common.core.domain.AjaxResult;
import common.enums.BusinessType;
import common.utils.poi.ExcelUtil;
import common.core.page.TableDataInfo;

/**
 * 用品采购Controller
 * 
 * @author ruoyi
 * @date 2022-06-08
 */
@RestController
@RequestMapping("/system/caigou")
public class CaigouController extends BaseController
{
    @Autowired
    private ICaigouService caigouService;

    /**
     * 查询用品采购列表
     */
    @PreAuthorize("@ss.hasPermi('system:caigou:list')")
    @GetMapping("/list")
    public TableDataInfo list(Caigou caigou)
    {
        startPage();
        List<Caigou> list = caigouService.selectCaigouList(caigou);
        return getDataTable(list);
    }

    /**
     * 导出用品采购列表
     */
    @PreAuthorize("@ss.hasPermi('system:caigou:export')")
    @Log(title = "用品采购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Caigou caigou)
    {
        List<Caigou> list = caigouService.selectCaigouList(caigou);
        ExcelUtil<Caigou> util = new ExcelUtil<Caigou>(Caigou.class);
        util.exportExcel(response, list, "用品采购数据");
    }

    /**
     * 获取用品采购详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:caigou:query')")
    @GetMapping(value = "/{caigouid}")
    public AjaxResult getInfo(@PathVariable("caigouid") Long caigouid)
    {
        return AjaxResult.success(caigouService.selectCaigouByCaigouid(caigouid));
    }

    /**
     * 新增用品采购
     */
    @PreAuthorize("@ss.hasPermi('system:caigou:add')")
    @Log(title = "用品采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Caigou caigou)
    {
        return toAjax(caigouService.insertCaigou(caigou));
    }

    /**
     * 修改用品采购
     */
    @PreAuthorize("@ss.hasPermi('system:caigou:edit')")
    @Log(title = "用品采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Caigou caigou)
    {
        return toAjax(caigouService.updateCaigou(caigou));
    }

    /**
     * 删除用品采购
     */
    @PreAuthorize("@ss.hasPermi('system:caigou:remove')")
    @Log(title = "用品采购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caigouids}")
    public AjaxResult remove(@PathVariable Long[] caigouids)
    {
        return toAjax(caigouService.deleteCaigouByCaigouids(caigouids));
    }
}
